Ext.define('Ext.desk.Control.Configer',{
	extend: 'Ext.window.Window',
	alias: 'widget.systemconfig',
	title: '个性化设置',
	iconCls: 'icon-options',
	width: 400,
	height: 150,
	closeAction: 'hide',
	layout: 'fit',
//	border : false,
	modal: true,
	frame: true,
	buttonAlign: 'center',
    initComponent: function () {
        var me = this;
        var raws = {};
        var formp = Ext.create('Ext.form.Panel',{
        	border: false,
        	bodyPadding: 15,
        	defaults: {labelWidth: 65,anchor: '100%',allowBlank: false},
        	items: [{
        		fieldLabel: '主题选择',
        		xtype: 'combobox',
        		name: 'skin',
        		value: 'ext-all-green.css',
				store: {
					xtype: 'store',
					fields: ['v', 'p'],
				    data : [{p: '默认', v: 'ext-all.css'},
				            {p: '板岩', v: 'ext-all-slate.css'},
				            {p: '灰色', v: 'ext-all-gray1.css'},
				            {p: '绿色', v: 'ext-all-green.css'},
				            {p: '粉红', v: 'ext-all-pink.css'},
				            {p: '紫色', v: 'ext-all-purple.css'},
				            {p: '红色', v: 'ext-all-red.css'}]
				},
			    queryMode: 'local',
			    displayField: 'p',
			    valueField: 'v',
			    listeners: {
			    	select: function(f,recs){
			    		Ext.util.CSS.swapStyleSheet('theme', 'javascript/extjs-4.1.1/resources/myself/'+ f.getValue());
			    	}
			    }
        	},{
        		fieldLabel: '导航宽度',
        		xtype: 'numberfield',
        		name: 'navwidth',
        		value: 200,
        		minValue: 200,
        		maxValue: 400
        	}],
        	listeners: {
        		afterrender: function(){
        			Ext.Ajax.request({
					    url: 'user/getConfig.do',
					    success: function(response){
					    	raws = Ext.decode(response.responseText);
        	    	    	formp.form.setValues(raws);
					    }
					});
        		}
        	}
        });
        
        
        me.items = [formp];
        me.buttons = [{
        	text: '保存',
        	handler: function(){
    	    	var form = formp.form;
    	    	if(form.isValid()){
            		var values = formp.form.getValues();
    	    		form.submit({
        	    	    url: 'user/saveConfig.do',
        	    	    params: {configs: Ext.encode(form.getValues())},
        	    	    success: function(form, action) {
        	    	    	var rs = Ext.decode(action.response.responseText);
        	    	    	if(rs.rst){
        	    	    		var nvp = Ext.getCmp('sys-desk-navigation').ownerCt;
        	            		nvp.setWidth(Number(values.navwidth));
        	    	    		Ext.Msg.alert('提示', '保存成功！');
        	    	    		formp.up('window').close();
        	    	    	}
        	    	    	else{
        	    	    		Ext.Msg.alert('提示', '保存失败！详情：<br>'+rs.msg);
        	    	    	}
        	    	    }
        	    	});
    	    	}
    	    	else{
    	    		Ext.Msg.alert('提示', '无效的配置信息,请正确填写配置信息！');
    	    	}
        	}
        },{
        	text: '重置',
        	handler: function(){
        		Ext.Ajax.request({
				    url: 'user/getDefaultConfig.do',
				    success: function(response){
				    	var cfg = Ext.decode(response.responseText);
    	    	    	formp.form.setValues(cfg);
    	    	    	Ext.util.CSS.swapStyleSheet('theme', 'javascript/extjs-4.1.1/resources/myself/'+ cfg.skin);
				    }
				});
        	}
        },{
        	text: '取消',
        	handler: function(){
        		this.up('window').close();
        		Ext.Ajax.request({
				    url: 'user/getIndividuality.do',
				    success: function(response){
				    	var cfg = Ext.decode(response.responseText);
    	    	    	formp.form.setValues(cfg);
    	    	    	Ext.util.CSS.swapStyleSheet('theme', 'javascript/extjs-4.1.1/resources/myself/'+ cfg.skin);
				    }
				});
        	}
        }];
        me.callParent();
    }
});